package org.jeecgframework.web.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.jeecgframework.core.common.controller.BaseController;
import org.jeecgframework.core.common.model.json.AjaxJson;
import org.jeecgframework.web.service.UploadContactsService;
import org.jeecgframework.web.system.pojo.base.ZyContactsEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

/**   
 * @Title: UploadContactsService
 * @Description: 上传联系信息
 * @author ZhangYunlong
 * @date 2016-04-01
 * @version V1.0   
 *
 */
@Scope("prototype")
@Controller
@RequestMapping("/uploadContactsController")
public class UploadContactsController extends BaseController {

	@Autowired
	private UploadContactsService uploadContactsService;
	/**
	 * 设备以及备件信息列表 页面跳转
	 * @return
	 */
	@RequestMapping(params = "uploadFile")
	public ModelAndView uploadFile(HttpServletRequest request) {
		return new ModelAndView("com/zybk/file_upload/uploadContacts");
	}
	
	@RequestMapping(params = "importExcel", method = RequestMethod.POST)
	@ResponseBody
	public AjaxJson importExcel(HttpServletRequest request, HttpServletResponse response) throws IOException {
		System.out.println("进入导入联系人ACTION----");
		AjaxJson j = new AjaxJson();
		List<ZyContactsEntity> excelList = uploadContactsService.parseExcel(request);
		System.out.println("开始保存数据----");
		uploadContactsService.batchSave(excelList);
		System.out.println("----保存数据完毕----");
		j.setMsg("导入成功");
		return j;	
	}
}
